<template>
  <a-modal
    title="选择人员"
    :width="1024"
    :visible="visible"
    :confirmLoading="loading"
    @ok="modalOk"
    @cancel="() => { $emit('cancel') }"
  >
    <s-table
      ref="table"
      :columns="columns"
      :rowSelection="rowSelection"
      :data="loadData"
      :row-key="(record)=>record.id"
      :showPagination="true"
    >
    </s-table>
  </a-modal>
</template>

<script>
import { getMemberLists } from '@/api/manage'
import { STable } from '@/components'

export default {
  name: 'SelectMember',
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    loading: {
      type: Boolean,
      default: () => false
    }
    // model: {
    //   type: Object,
    //   default: () => null
    // }
  },
  data () {
    return {
      rowSelection: {
        type: 'radio',
        onSelect: (record, selected, selectedRows, nativeEvent) => {
          this.onSelect(record, selected, selectedRows, nativeEvent)
        }
      },
      nowSelect: {

      },
      model: {},
      detailOnlyVisible: false,
      bandTickVisible: false,
      detailVisible: false,
      deliveryVisible: false,
      queryParam: {},
      departmentList: [],
      columns: [
        {
          title: '#',
          dataIndex: 'id'
        },
        {
          title: '人员姓名',
          dataIndex: 'name'
        },
        {
          title: '性别',
          dataIndex: 'gender'
        },
        {
          title: '手机号',
          dataIndex: 'cellPhone'
        },
        {
          title: '是否管理员',
          dataIndex: 'isAdmin',
          customRender: (text) => { return (text === 1) ? '是' : '否' }
        },
        {
          title: '部门',
          dataIndex: 'department.departName'
        }
      ],
      loadData: parameter => {
        // 不要在这里修改分页大小，STable已经写死默认每一页10条
        const cParameter = { pageSize: parameter.pageSize, pageNum: parameter.pageNo }
        const requestParameter = Object.assign({}, cParameter, this.queryParam)
        return new Promise((resolve, reject) => {
          getMemberLists(requestParameter).then(res => {
            this.departmentList = res.data
            res.data.forEach((item) => {
              item.addtime = this.Format(item.addtime, 'yyyy-MM-dd hh:mm:ss')
            })
            resolve({
              data: res.data,
              totalCount: parseInt(res.headers['x-count']),
              pageNo: parameter.pageNo,
              pageSize: parameter.pageSize
            })
            // return {
            //   data: res.data,
            //   totalCount: parseInt(res.headers['x-count']),
            //   pageNo: parameter.pageNo,
            //   pageSize: parameter.pageSize
            // }
          })
        })
      }
    }
  },
  components: {
    STable
  },
  created () {
    // this.init()
  },
  methods: {
    onSelect (record, selected, selectedRows, nativeEvent) {
      this.nowSelect = record
    },
    modalOk () {
      this.$emit('OnSelect', this.nowSelect)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>

</script>
